package com.fan.admin.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.fan.commons.pojo.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author fan
 * @date 2021/3/10
 */
@Component
public class JwtUtil {

	@Value("${fan.jwt.secret}")
	private String secret;

	public void getJwt(User user) {
		Algorithm algorithm = Algorithm.HMAC256(secret);
		String token = JWT.create()
				.withExpiresAt(user.getDate())
				.withClaim("id", user.getId())
				.withClaim("userId", user.getUserId())
				.withClaim("name", user.getName())
				.withClaim("role", user.getRole())
				.sign(algorithm);
	}
}
